#!/bin/bash
basepath=$(cd $(dirname ${BASH_SOURCE[0]}) >/dev/null && pwd)
sed -i "7ainclude_directories(/usr/local/gatk/gkl-0.8.10/AvxToNeon-1.0.0)" $basepath/GKL-0.8.10/CMakeLists.txt
sed -i "s/#include <x86intrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "s/#include <cpuid.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "32a\    #include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "42c\/*\    uint32_t xcr0;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "48a*\/" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "49a\    return false;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "57c\/\/    uint32_t xcr0;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "58c\/\/    uint32_t zmm_ymm_xmm = (7 << 5) | (1 << 2) | (1 << 1);" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "59c\/\/#if defined(_MSC_VER)" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "61c\/\/    xcr0 = (uint32_t)_xgetbv(0);" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "62c\/\/#else" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "63c\/\/    __asm__ (\"xgetbv\" : \"=a\" (xcr0) : \"c\" (0) : \"%edx\");" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "64c\/\/#endif" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "66c\/\/    return ((xcr0 & zmm_ymm_xmm) == zmm_ymm_xmm);" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "66a\    return false;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "76c\/*\    uint32_t a, b, c, d;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "90a*\/" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "91a\    return true;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "101c\/*\    uint32_t a, b, c, d;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "126c*\/" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "135a\/*" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "168a*\/" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "169a\    return true;" $basepath/GKL-0.8.10/src/main/native/common/avx.h
sed -i "s/# include <x86intrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/encode_df.c
sed -i "11a# include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/encode_df.c
sed -i "s/# include <immintrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/huff_codes.h
sed -i "40a# include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/huff_codes.h
sed -i "s/# include <x86intrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/huff_codes.h
sed -i "45a# include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/huff_codes.h
sed -i "s/# include <x86intrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/huffman.h
sed -i "41a# include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/compression/isa-l-master/igzip/huffman.h
sed -i "26a# include \"avx_extra.h\"" $basepath/GKL-0.8.10/src/main/native/pairhmm/avx-types.h
sed -i "s/set_property/#&/g" $basepath/GKL-0.8.10/src/main/native/pairhmm/CMakeLists.txt
sed -i "93c\  \/\/if (_MM_GET_FLUSH_ZERO_MODE() != _MM_FLUSH_ZERO_ON) {" $basepath/GKL-0.8.10/src/main/native/pairhmm/IntelPairHmm.cc
sed -i "94c\  \/\/  DBG(\"Flush-to-zero (FTZ) is enabled when running PairHMM\");" $basepath/GKL-0.8.10/src/main/native/pairhmm/IntelPairHmm.cc
sed -i "95c\  \/\/}" $basepath/GKL-0.8.10/src/main/native/pairhmm/IntelPairHmm.cc
sed -i "96c\  \/\/_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);" $basepath/GKL-0.8.10/src/main/native/pairhmm/IntelPairHmm.cc
sed -i "s/#include <x86intrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/pairhmm/pairhmm_common.h
sed -i "30a\  #include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/pairhmm/pairhmm_common.h
sed -i "45c#include \"smith_avxextra.h\"" $basepath/GKL-0.8.10/src/main/native/smithwaterman/avx2-functions.h
sed -i "98c\    (__m256i)rev_interpret(_mm256_blendv_ps(interpret(__v1), (__m256)interpret(__v2), (__m256)interpret(__mask)))" $basepath/GKL-0.8.10/src/main/native/smithwaterman/avx2-functions.h
sed -i "s/set_property/#&/g" $basepath/GKL-0.8.10/src/main/native/smithwaterman/CMakeLists.txt
sed -i "7aset_property(SOURCE avx2_impl.cc APPEND_STRING PROPERTY COMPILE_FLAGS \" -march=armv8-a+fp+simd+crc \")" $basepath/GKL-0.8.10/src/main/native/smithwaterman/CMakeLists.txt
sed -i "9aset_property(SOURCE avx512_impl.cc APPEND_STRING PROPERTY COMPILE_FLAGS \" -march=armv8-a+fp+simd+crc \")" $basepath/GKL-0.8.10/src/main/native/smithwaterman/CMakeLists.txt
sed -i "s/#include <immintrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/smithwaterman/IntelSmithWaterman.cc
sed -i "34a#include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/smithwaterman/IntelSmithWaterman.cc
sed -i "25a#include \"smith_avxextra.h\"" $basepath/GKL-0.8.10/src/main/native/smithwaterman/PairWiseSW.h
sed -i "s/#include <x86intrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/smithwaterman/smithwaterman_common.h
sed -i "30a\  #include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/smithwaterman/smithwaterman_common.h
sed -i "s/#include <immintrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/smithwaterman/smithwaterman_common.h
sed -i "38a#include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/smithwaterman/smithwaterman_common.h
sed -i "s/#include <x86intrin.h>/\/\/&/" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "27a\  #include \"avx2neon.h\"" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "46s/value = /&0;\/\//" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "58,65s/^/\/\//" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "76s/^/\/\//" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "76a\    return 1;" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "88s/^/\/\//" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "88a\    return 1;" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "100s/^/\/\//" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "100a\    return 1;" $basepath/GKL-0.8.10/src/main/native/utils/utils.cc
sed -i "120s/^/\/\//" $basepath/GKL-0.8.10/build.gradle
